

import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSourceFactory;

import com.bj58.groupbuy.util.PathUtil;
import com.bj58.zhaoxiang.model.UserInfo;

public class CityDao {

	public DispLocal getDispLocalById(int local_id) throws SQLException {
		UserInfo userInfo = new UserInfo();
		DataSource dataDource = createDataSource(1);
		Connection con = dataDource.getConnection();
		Statement st = null;
		ResultSet rs = null;
		String sql = "select * from user_info where user_name='"+userName.trim()+"';";
		try {
			st = con.createStatement();
			rs = st.executeQuery(sql);
			rs.next();
			userInfo.setUser_id(rs.getString("user_id"));
			userInfo.setUserName(rs.getString("user_name"));
			userInfo.setCity_id(rs.getString("city_id"));
			userInfo.setCity_name(rs.getString("city_name"));
			userInfo.setComment(rs.getString("comment"));
			userInfo.setEmail(rs.getString("email"));
			userInfo.setMobile(rs.getString("mobile"));
			userInfo.setPassword(rs.getString("password"));
			if (rs != null)
				rs.close();
			if (st != null)
				st.close();
			if (con != null)
				con.close();
			rs = null;
			st = null;
			con = null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return userInfo;
	}

	/**
	 * 创建一个新的数据库连接池
	 * 
	 * @param name
	 *            JNDI的搜索名
	 * @param record
	 *            数据库连接池的基本信息
	 * @param constants
	 *            系统内置的环境管理类
	 * @return 新的数据库连接池，null表示创建失败
	 */
	private static DataSource createDataSource(int type) {
		String name = "";
		DataSource dataSource = null;
		try {
			File propfile = null;
			String path = "";
			if (type == 1) {
				path = PathUtil.getWFNamespaceFolder()
						+ "/zhaoxiang_r.properties";
				;
			}

			propfile = new File(path);

			Properties p = new Properties();
			FileInputStream fis = new FileInputStream(propfile);
			p.load(fis);
			fis.close();
			name = p.getProperty("name");

			dataSource = BasicDataSourceFactory.createDataSource(p);

			// log.debug("DbPool: 创建数据库连接池：" + name);
		} catch (Exception e) {
			// log.error("DbPool: 创建数据源 " + name + " 失败：",e);
		}
		return dataSource;
	}
}
